//
//  RollOutViewController.m
//  NiuBanJin
//
//  Created by zf on 15/10/21.
//  Copyright © 2015年 zzjr. All rights reserved.
//

//转出页面

#import "RollOutViewController.h"
#import "AssetDetailsViewController.h"
#import "AddressSelectionController.h"
#import "PasswordEnterView.h"
#import "PasswordTextField.h"
#import "UsefulUtil.h"
#import "Province.h"
#import "City.h"
#import "Country.h"
#import "ProvinceController.h"

@interface RollOutViewController () <UITextFieldDelegate>

@property (nonatomic, strong) NSMutableDictionary *mutableDictionary_headerData;//网络来的银行卡卡号等信息
@property (nonatomic, strong) NSMutableArray *mutableArray_provinceList;//省信息

@property (nonatomic, copy) NSString *str_cardNo;//卡号
@property (nonatomic, copy) NSString *str_fee;//费用
@property (nonatomic, copy) NSString *str_amount;//转出多少
@property (nonatomic, copy) NSString *str_getAmount;//实际得到多少
@property (nonatomic, copy) NSString *str_succType;//转出类型
@property (nonatomic , copy) NSString *str_receive;//实收
@property (nonatomic, assign) float button_y; //转出按钮的默认位置
@end

@implementation RollOutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [UsefulUtil clearAddressInfoFromUserDefault];// 清除地址信息
    [self pageSettingsAndSubviewsCreation];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self getDataFromserver]; //保证每次都是最新数据
    
    BCTextField *textFiled = [self.view viewWithTag:22];
    if ([textFiled.text isEqualToString:@""] || [textFiled.text isEqualToString:@"0"]) {
        
        [textFiled setText:@""];
    }
}

#pragma mark - data prepration

-(void) getDataFromserver {
    
    NSDictionary *dic_withdraw = @{@"userId":GETCURRENTUSERINOBYPRAMETERES(user_userId),@"token":GETCURRENTUSERINOBYPRAMETERES(user_userToken)};

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [[NetworkUtil sharedNetworkUtil] zzjrTrade_transfer_to_withdrawByParmeteres:dic_withdraw transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        if (!error) {
            
            NSDictionary *dic_result = parsedData;
            
            if ([dic_result[@"status"] integerValue] == 0) {
                
                if ([dic_result[@"result"][@"succType"] integerValue] == 1) {
                    
                    self.str_succType = @"1";
                    
                    [self.mutableDictionary_headerData setObject:dic_result[@"result"][@"cardNo"] forKey:@"cardNo"];
                    [self.mutableDictionary_headerData setObject:dic_result[@"result"][@"curUsableAmount"] forKey:@"curUsableAmount"];
                    [self.mutableDictionary_headerData setObject:dic_result[@"result"][@"bankName"] forKey:@"bankName"];
                    
                    //隐藏显示地区界面
                    
                    [self hideAddressLabel];
                    
                }else if ([dic_result[@"result"][@"succType"] integerValue] == 2) { //防止server传递其它值出来

                    self.str_succType = @"2";
                    
                    [self.mutableArray_provinceList removeAllObjects]; //清空 省信息
                    
                    [self.mutableDictionary_headerData setObject:dic_result[@"result"][@"cardNo"] forKey:@"cardNo"];
                    [self.mutableDictionary_headerData setObject:dic_result[@"result"][@"curUsableAmount"] forKey:@"curUsableAmount"];
                    [self.mutableDictionary_headerData setObject:dic_result[@"result"][@"bankName"] forKey:@"bankName"];
                    
                    [self getProvinceListByArray:dic_result[@"result"][@"provList"]]; //取省的list
                    
                    if ([self.mutableDictionary_headerData count] > 0) {
                        
                        [self updateUI];
                    }
                }
            }else { //服务器出错
                
                [UsefulUtil showAlertView:parsedData[@"msg"]];
            }
            
        }else { //网络错误，将来替换成网络错误的文案
            
            [UsefulUtil showAlertView:error.description];
        }
    }];
}

//得到所有的省列表

- (void) getProvinceListByArray:(NSArray *) array {
    
    for (NSDictionary *dic_element in array) {
        
        Province *tmp = [[Province alloc] initWithAttributes:dic_element];
        [self.mutableArray_provinceList addObject:tmp];
    }
}

- (void) hideAddressLabel { //因为已经成功转出过了，所以这儿要隐藏
    
    UIView *line = [[self.view viewWithTag:23] viewWithTag:24];
    UILabel *label_address = [self.view viewWithTag:500];
    
    [label_address setHidden:YES];
    
    UIView *view_cover = [UsefulUtil viewCreationWithFrame:CGRectMake(0, line.frame.origin.y, SCREEN_WIDTH, MULTIPLYHEIGHT(102.0/2)) backgroundColor:BASECOLOR backGroundImage:nil];
    
    UIView *view_arraow = [self.view viewWithTag:25];
    
    [line.superview addSubview:view_cover];
    [view_arraow setHidden:YES];
    
    // 将button和文字提高
    
    UIButton *button  = [self.view viewWithTag:27];
    
    self. button_y =  MULTIPLYHEIGHT(580.0/2); //ios 底层会复用VIEW，所有这个值只能用一次 ＝＝》BUG 296
    
    
    UILabel *label_text = [self.view viewWithTag:28];
    
    
    [UIView animateWithDuration:0.1 animations:^{
        
        button.frame = CGRectMake(button.frame.origin.x, self. button_y  - MULTIPLYHEIGHT(102.0/2), button.bounds.size.width, button.bounds.size.height);
    }];
    
    [UIView animateWithDuration:0.1 animations:^{
        
        label_text.frame = CGRectMake(label_text.frame.origin.x,button.frame.origin.y +button.bounds.size.height+ MULTIPLYHEIGHT(20.0/2), label_text.bounds.size.width, label_text.bounds.size.height);
    }];
    
    //更新其它UI
    [self updateUI];
}

- (void) updateUI { //更新显示的钱 etc ..
    
    //余额
    UILabel *label_balance = [self.view viewWithTag:21];
    
    [label_balance setText:self.mutableDictionary_headerData[@"curUsableAmount"]];
    
    //银行
    UILabel *label_bank = [self.view viewWithTag:30];
    
    self.str_cardNo = self.mutableDictionary_headerData[@"cardNo"];
    
    NSString *name = self.mutableDictionary_headerData[@"bankName"];
    
    [label_bank setText:[NSString stringWithFormat:@"%@尾号%@",name,[self.str_cardNo substringWithRange:NSMakeRange(self.str_cardNo.length - 4, 4)]]];

    //地址
    
    if ([self.str_succType isEqualToString:@"2"] &&  [UsefulUtil getCustomObjectByKey:@"country"]) {
        
        UILabel *label_address = [self.view viewWithTag:500];
        [label_address setTextColor:[UsefulUtil colorWithHexString:@"#434343"]];
        
        Province *province = (Province *)[UsefulUtil getCustomObjectByKey:@"province" ];
        City *city = (City *)[UsefulUtil getCustomObjectByKey:@"city" ];
        Country *country = (Country *)[UsefulUtil getCustomObjectByKey:@"country" ];
        
        [label_address setText:[NSString stringWithFormat:@"%@ %@ %@",province.province_name,city.city_name,country.country_name]];
    }
}

#pragma mark - SubviewsCreationAndPageSettings

- (void) pageSettingsAndSubviewsCreation {
    
    self.navigationItem.title = @"转出";
    self.view.backgroundColor = BASECOLOR;
    
    [super setRightBarButtonItemTitle:@"转出记录" imageName:@"record" actionName:@selector(rightButtonAction)];
    // 图片在前，文字在后
    
    UIButton *button_rightItem = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(160.0/2), MULTIPLYHEIGHT(44.0))];
    [button_rightItem setTitle:@"转出记录"  forState:UIControlStateNormal];
    [button_rightItem setTitleColor:[UsefulUtil colorWithHexString:@"#fb4747"] forState:UIControlStateNormal];
    [button_rightItem.titleLabel setFont:[UIFont systemFontOfSize:15.0]];
    [button_rightItem addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    // 图片
    CALayer *layer_icon = [CALayer layer];
    
    [layer_icon setFrame:CGRectMake(0,MULTIPLYHEIGHT(31.0/2), MULTIPLYWIDTH(26.0/2), MULTIPLYHEIGHT(26.0/2))];
    [button_rightItem.layer addSublayer:layer_icon];
    
    [layer_icon setContents:(__bridge id)[UIImage imageNamed:@"record"].CGImage];
    
    [button_rightItem setTitleEdgeInsets:UIEdgeInsetsMake(0, MULTIPLYWIDTH(8.0), 0, 0)];
    [button_rightItem.titleLabel setAdjustsFontSizeToFitWidth:YES];
    [button_rightItem.titleLabel setTextAlignment:NSTextAlignmentRight];
    UIBarButtonItem *barItemRight = [[UIBarButtonItem alloc] initWithCustomView:button_rightItem];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                       target:nil action:nil];
    /**
     *  width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和边界间距为5pix，所以width设为-5时，间距正好调整
     *  为0；width为正数时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacer.width = MULTIPLYWIDTH(-10.0);
    [self.navigationItem setRightBarButtonItems:@[negativeSpacer,barItemRight]];

    
    
    //上面白色UI
    
    UIView *view_white = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(100))];
    view_white.backgroundColor = [UsefulUtil colorWithHexString:@"#ffffff"];
    [self.view addSubview:view_white];
    UILabel *label_balance = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(125), MULTIPLYHEIGHT(21), MULTIPLYWIDTH(120), MULTIPLYHEIGHT(15))];
    label_balance.text = @"当前钱包余额(元)";
    label_balance.adjustsFontSizeToFitWidth = YES;
    
    [self.view addSubview:label_balance];
    
    UILabel *label_balanceNumber = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(110), CGRectGetMaxY(label_balance.frame) + MULTIPLYHEIGHT(10), MULTIPLYWIDTH(150), MULTIPLYHEIGHT(40))];
    label_balanceNumber.text = GETCURRENTUSERINOBYPRAMETERES(user_userAsset);
    label_balanceNumber.adjustsFontSizeToFitWidth = YES;
    label_balanceNumber.textColor = [UsefulUtil colorWithHexString:@"#Fb4747"];
    label_balanceNumber.textAlignment = NSTextAlignmentCenter;
    label_balanceNumber.font = [UIFont systemFontOfSize:40];
    label_balanceNumber.tag = 21;
    
    [self.view addSubview:label_balanceNumber];
    
    UIView *view_tab = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(view_white.frame) + MULTIPLYHEIGHT(20), SCREEN_WIDTH, MULTIPLYHEIGHT(150))];
    
    view_tab.backgroundColor = [UsefulUtil colorWithHexString:@"#ffffff"];
    
    [view_tab setTag:23];
    [self.view addSubview:view_tab];
    
    //转出的数量
    
    BCTextField *field_rollOutMoney = [[BCTextField alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(130), CGRectGetMinY(view_tab.frame) + MULTIPLYHEIGHT(18), MULTIPLYWIDTH(200), MULTIPLYHEIGHT(20))];
    field_rollOutMoney.textAlignment = NSTextAlignmentNatural;
    [field_rollOutMoney becomeFirstResponder];
    [field_rollOutMoney setTag:22];
    [field_rollOutMoney setDelegate:self];
    [field_rollOutMoney setRegx:@"^[0-9]{0,6}+(\\.[0-9]{0,2})?$"];
    field_rollOutMoney.adjustsFontSizeToFitWidth = YES;
    field_rollOutMoney.textAlignment = NSTextAlignmentLeft;
    field_rollOutMoney.keyboardType = UIKeyboardTypeDecimalPad;
    field_rollOutMoney.placeholder = @"请输入提现金额";
    
    [self.view addSubview:field_rollOutMoney];
    
    // 中间的label
    
    NSArray *array_rollOut = @[@"转出金额 (元)" ,  @"提现银行卡" , @"银行卡所属地" ];
    
    for (int i = 0; i < 3; i++) {
        
        UIView *view_crossLine = [[UIView alloc]initWithFrame:CGRectMake(0, MULTIPLYHEIGHT(50) * i + MULTIPLYHEIGHT(50), SCREEN_WIDTH, MULTIPLYHEIGHT(1))];
        view_crossLine.backgroundColor = [UsefulUtil colorWithHexString:@"#c8c7cc"];
        [view_tab addSubview:view_crossLine];
        
        if (i == 1) {
            
            view_crossLine.tag = 24;
        }
        
        UILabel *label_rollOut = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(15), MULTIPLYHEIGHT(18) + MULTIPLYHEIGHT(50) * i, MULTIPLYWIDTH(120), MULTIPLYHEIGHT(15))];
        label_rollOut.text = [array_rollOut objectAtIndex:i];
        label_rollOut.font = [UIFont systemFontOfSize:15.0];
        label_rollOut.textColor = [UsefulUtil colorWithHexString:@"#434343"];
        label_rollOut.adjustsFontSizeToFitWidth = YES;
        
        if (i == 2) { //为银行卡所属地加手势
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addressesAction:)];
            label_rollOut.userInteractionEnabled = YES;
            [label_rollOut addGestureRecognizer:tap];
        }
        
        [view_tab addSubview:label_rollOut];
    }
    
    
    UILabel *label_bankCard = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(field_rollOutMoney.frame), CGRectGetMinY(field_rollOutMoney.frame) + MULTIPLYHEIGHT(100.0 / 2), MULTIPLYWIDTH(240), MULTIPLYHEIGHT(15))];
    label_bankCard.font = [UIFont systemFontOfSize:15.0];
    label_bankCard.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    label_bankCard.text = @"";
    [label_bankCard setTag: 30];
    [self.view addSubview:label_bankCard];
    
    
    //银行所属地
    
    UILabel *label_address = [[UILabel alloc]initWithFrame:CGRectMake(field_rollOutMoney.frame.origin.x, CGRectGetMinY(label_bankCard.frame) + MULTIPLYHEIGHT(50), SCREEN_WIDTH - field_rollOutMoney.frame.origin.x - MULTIPLYWIDTH(30.0) , MULTIPLYHEIGHT(15))];
    [self.view addSubview:label_address];
    
    label_address.tag = 500;
    label_address.text = @"请选择所属地";
    label_address.font = [UIFont systemFontOfSize:15.0];
    label_address.textColor = [UsefulUtil colorWithHexString:@"#c7c7cd"];
    label_address.adjustsFontSizeToFitWidth = YES;
    label_address.userInteractionEnabled = YES;
    
    // 添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addressesAction:)];
    [label_address addGestureRecognizer:tap];
    
    
    
    UIView *view_address = [[UIView alloc]init];
    view_address.frame = CGRectMake(CGRectGetMaxX(label_address.frame), CGRectGetMinY(label_address.frame), MULTIPLYWIDTH(20), MULTIPLYHEIGHT(15));
    
    [view_address setTag:25];
    [self.view addSubview:view_address];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addressesAction:)];
    
    [view_address addGestureRecognizer:tapGesture];
    
    UIImageView *image_address = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, MULTIPLYWIDTH(12), MULTIPLYHEIGHT(15))];
    image_address.image = [UIImage imageNamed:@"arrows.png"];
    [view_address addSubview:image_address];
    
    // 转出按钮
    
    UIButton *button_rollOut = [UIButton buttonWithType:UIButtonTypeSystem];
    button_rollOut.frame = CGRectMake(MULTIPLYWIDTH(15), CGRectGetMaxY(view_tab.frame) + MULTIPLYHEIGHT(31), SCREEN_WIDTH - MULTIPLYWIDTH(30), MULTIPLYHEIGHT(50));
    
    [button_rollOut setTitle:@"转出" forState:UIControlStateNormal];
    button_rollOut.backgroundColor = [UsefulUtil colorWithHexString:@"#Fb4747"];
    button_rollOut.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [button_rollOut addTarget:self action:@selector(rollOutAction:) forControlEvents:UIControlEventTouchUpInside];
    button_rollOut.tintColor = [UIColor whiteColor];
    [button_rollOut setTag:27];
    [self.view addSubview:button_rollOut];
    
    NSString *str_rollOutRule = @"转出说明:\n1.单笔1-1000000元\n2.工作日(9:00~14:30)预计2小时到账(14:30后申请的将在次日到账)\n3.周末节假日顺延\n4.当日充值款当日提现手续费0.24%,最低1元\n5.启动期转出手续费为0元";
    UILabel *label_rollOutRule = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(15.0), CGRectGetMaxY(button_rollOut.frame) + MULTIPLYHEIGHT(22.0 / 2) , MULTIPLYWIDTH(360), MULTIPLYHEIGHT(106))];
    label_rollOutRule.tag = 28;
    label_rollOutRule.text = str_rollOutRule;
    label_rollOutRule.adjustsFontSizeToFitWidth = YES;
    label_rollOutRule.font = [UIFont systemFontOfSize:11];
    label_rollOutRule.numberOfLines = 0;
    label_rollOutRule.textColor = [UsefulUtil colorWithHexString:@"#989898"];
    
    [self.view addSubview:label_rollOutRule];
}

#pragma mark -addressesAction

-(void)addressesAction:(UITapGestureRecognizer *) tap { //选择地址区域的方法

    ProvinceController *addressVC = [[ProvinceController alloc]init];
    [addressVC setArray_provinces:self.mutableArray_provinceList];
    
    [self.navigationController pushViewController:addressVC animated:YES];
}

#pragma mark -getCityName

-(void)getCityName:(NSString *)cityName {
    
    UILabel *label = (UILabel *)[self.view viewWithTag:500];
    label.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    label.text = cityName;
}

#pragma mark -rollOutAction

- (void)rollOutAction:(UIButton *)sender {
    
    [self.view endEditing:YES];
   // 常规检测
    BCTextField *textFiled = [self.view viewWithTag:22];
    UILabel *label_address = [self.view viewWithTag:500];
    
    self.str_amount = textFiled.text;
    
    if ([self.str_amount isEqualToString:@""] || self.str_amount.floatValue <= 0.00) {
        
        [UsefulUtil showAlertView:@"转出金额不能为空或小于等于0"];

        return;
    }else if(self.str_amount.floatValue > [self.mutableDictionary_headerData[@"curUsableAmount"] floatValue] ){
        
        [UsefulUtil showAlertView:@"余额不足"];
        
        return;
        
    }else {
        
        if( [self.str_succType isEqualToString:@"1"]){ //如果等于表明已经转出过
            
            [self getWithDrawFee]; //计算费用
        }else { //没转出过要检测值
            
            if ([label_address.text isEqualToString:@"请选择所属地"]) {
                
                [UsefulUtil showAlertView:@"银行卡归属地不能为空!"];
                
                return;
            }
            [self getWithDrawFee];        //开始得到fee的接口
        }
    }

}

- (void) getWithDrawFee {
    
    NSDictionary *dic_params = @{@"userId":GETCURRENTUSERINOBYPRAMETERES(user_userId),@"token":GETCURRENTUSERINOBYPRAMETERES(user_userToken),@"amount":self.str_amount };
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [[NetworkUtil sharedNetworkUtil] zzjrTradeFeeByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {

        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if (!error) {
            
            NSDictionary *dic_result = parsedData;
            
            if ([dic_result[@"status"] integerValue] == 0) {
               
                self.str_getAmount = [dic_result[@"result"] objectForKey:@"actualAmount"];
                self.str_receive = [dic_result[@"result"] objectForKey:@"withdrawFee"];
                
                [self popUpPasswordUI]; //弹出密码框
                
            }else { //服务器出错
                
                [UsefulUtil showAlertView:parsedData[@"msg"]];
            }
            
        }else { //网络错误，将来替换成网络错误的文案
            
            [UsefulUtil showAlertView:error.description];
        }
        
    }];
 
}

- (void) popUpPasswordUI { //要重写
    
    UIView *view_bg = [UsefulUtil viewCreationWithFrame:CURRENT_WINDOW.frame backgroundColor:[UIColor blackColor] backGroundImage:nil];
    
    [view_bg setAlpha:0.5];
    view_bg.tag = 600;
    
    [self.view.window addSubview:view_bg];
    
    UIView *view_roll = [[UIView alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(40.0 ), MULTIPLYHEIGHT(180.0), MULTIPLYWIDTH(560.0 / 2), MULTIPLYHEIGHT(504.0 / 2))];
    
    view_roll.backgroundColor = [UIColor whiteColor];
    view_roll.layer.cornerRadius = 8;
    view_roll.tag = 800;
    
    [self.view.window addSubview:view_roll];
    
    UILabel *label_titleMessage = [[UILabel alloc]initWithFrame:CGRectMake(0, MULTIPLYHEIGHT(37.0 / 2),  view_roll.frame.size.width, MULTIPLYHEIGHT(17.0))];
    
    label_titleMessage.text = @"请输入转出密码";
    
    label_titleMessage.textAlignment = NSTextAlignmentCenter;
    
    label_titleMessage.adjustsFontSizeToFitWidth = YES;
    
    label_titleMessage.font = [UIFont boldSystemFontOfSize:17];
    
    [view_roll addSubview:label_titleMessage];
    
    //上面的黑色分割线
    
    UIView *view_blackline = [[UIView alloc]initWithFrame:CGRectMake(0, MULTIPLYHEIGHT(98.0 / 2), view_roll.frame.size.width, MULTIPLYHEIGHT(1.0 /2))];
    
    view_blackline.backgroundColor = [UIColor blackColor];
    [view_roll addSubview:view_blackline];

    // 费用显示
    
    NSString *str_rollMoney = [NSString stringWithFormat:@"转出金额: %@元" , self.str_amount];
    NSString *str_realMoney = [NSString stringWithFormat:@"实际到账: %@元" , self.str_getAmount];
    
    CGFloat cgf_rollMoney =  str_realMoney.floatValue;
    CGFloat cgf_handleCharge = cgf_rollMoney * 0.25 / 100;
    NSString *str_handleCharge;
    if (cgf_handleCharge > 1) {
        
        str_handleCharge = [NSString stringWithFormat:@"手 续 费: %.2f元" , cgf_handleCharge];
    }else {
        
        str_handleCharge = [NSString stringWithFormat:@"手 续 费  : 1元" ];
    }
    NSString *str_realObtain = [NSString stringWithFormat:@"实  收      : %@元" , self.str_receive];
    
    NSArray *array_labeltext = @[str_rollMoney , str_realMoney , str_handleCharge , str_realObtain];
    NSArray *array_labelColor = @[[UsefulUtil colorWithHexString:@"#434343"] , [UsefulUtil colorWithHexString:@"#434343"] , [UsefulUtil colorWithHexString:@"#434343"] , REDCOLOR];
    
    for (int i = 0; i < 4; i++) {
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(40.0 / 2), CGRectGetMaxY(view_blackline.frame) + MULTIPLYHEIGHT(37.0/2) + MULTIPLYHEIGHT(30.0)*i , CGRectGetWidth(view_roll.frame) - MULTIPLYWIDTH(40.0 / 2 + 118.0 / 2) , MULTIPLYHEIGHT(30))];

        label.text = array_labeltext[i];
        
        label.textColor = array_labelColor[i];
        
        label.font = [UIFont systemFontOfSize:17.0];
        
        [view_roll addSubview:label];
    }
    
    //取消按钮
    
    UIButton *button_cancel = [UIButton buttonWithType:UIButtonTypeSystem];
    button_cancel.frame = CGRectMake( view_roll.frame.size.width - MULTIPLYWIDTH(33.0  ), MULTIPLYHEIGHT(40.0 / 2),MULTIPLYWIDTH(17.0) ,MULTIPLYHEIGHT(17.0) ) ;
//    [button_cancel setTitle:@"X" forState:UIControlStateNormal];
    [button_cancel setImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];
    button_cancel.titleLabel.font = [UIFont systemFontOfSize:19 ];
    button_cancel.titleLabel.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    [button_cancel addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [view_roll addSubview:button_cancel];
    
    //输入框1
    PasswordEnterView *view_password = [[PasswordEnterView alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(42.0 / 2), CGRectGetMaxY(view_blackline.frame) + MULTIPLYHEIGHT(300.0/2), MULTIPLYWIDTH(492.0 / 2),  MULTIPLYHEIGHT(82.0 / 2)) count:6 isCiphertext:YES textField:^(PasswordTextField *textField) {
        
        [textField becomeFirstResponder];
        
        textField = textField;
        
    }];
    
    [view_roll addSubview:view_password];
    
    //输入检测
    
    view_password.textDetail = ^(NSString *textDetail){
        
        if (textDetail.length == 6) {
            
            UIView *view_bg = [self.view.window viewWithTag:600];
            UIView *view_roll = [self.view.window  viewWithTag:800];
            
            [view_bg removeFromSuperview];
            [view_roll removeFromSuperview];
            
            [self realWithDrawWithPassword:textDetail];
        }
    };
   
}

- (void) realWithDrawWithPassword:(NSString *) pwd {
    
    NSDictionary *dic_params = nil;
    
    if ([self.str_succType isEqualToString:@"2"]) {
        
        Province *province = (Province *)[UsefulUtil getCustomObjectByKey:@"province" ];
        City *city = (City *)[UsefulUtil getCustomObjectByKey:@"city" ];
        Country *country = (Country *)[UsefulUtil getCustomObjectByKey:@"country" ];
        
        dic_params = @{
                                     
                                     @"userId":GETCURRENTUSERINOBYPRAMETERES(user_userId),
                                     @"token":GETCURRENTUSERINOBYPRAMETERES(user_userToken),
                                     @"withdrawAmount":self.str_amount,
                                     @"cardNo":self.str_cardNo,
                                     @"succType":self.str_succType,
                                     @"provinceId":province.province_id,
                                     @"provinceName":province.province_name,
                                     @"cityId":city.city_id,
                                     @"cityName":city.city_name,
                                     @"countyId":country.country_id,
                                     @"countyName":country.country_name,
                                     @"tradePassword":pwd
                                     };

    }else {
        
        dic_params = @{
                       
                       @"userId":GETCURRENTUSERINOBYPRAMETERES(user_userId),
                       @"token":GETCURRENTUSERINOBYPRAMETERES(user_userToken),
                       @"withdrawAmount":self.str_amount,
                       @"cardNo":self.str_cardNo,
                       @"succType":self.str_succType,
                       @"tradePassword":pwd
                       };
    }
    
    [MBProgressHUD showHUDAddedTo:self.view  animated:YES];
    
    [[NetworkUtil sharedNetworkUtil] zzjrTrade_real_withDrawByParmeteres:dic_params transferResultUsingBlock:^(id parsedData, NSError *error) {
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        if (!error) {
            
            NSDictionary *dic_result = parsedData;
            
            if ([dic_result[@"status"] integerValue] == 0 &&[dic_result[@"result"] integerValue] == 1) {
                
                UIAlertView *alert_success = [[UIAlertView alloc] initWithTitle:@"转出成功!" message:nil
                         delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
                
                [alert_success setTag:66];
                
                [alert_success show];
                
            } else {
             
                UIAlertView *alert_failed = [[UIAlertView alloc] initWithTitle:dic_result[@"msg"] message:nil
                                                                       delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"重试", nil];
                
                [alert_failed setTag:55];
                
                [alert_failed show];
            }
            
        }else {
            
            [UsefulUtil showAlertView:error.description];
        }
        
    }];
}

#pragma mark - alert view delegate 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    switch (alertView.tag) {
        case 66:
        {
            if (buttonIndex == 0) {
                
                [self.navigationController popViewControllerAnimated:YES];
            }
            
        }
            break;
        case 55:
        {
            if (buttonIndex == 1) { //重新支付
                
              [self popUpPasswordUI];
            }
        }
            break;
            
        default:
            
            break;
    }
    
}

#pragma mark - textfiled delegate

- (void)textFieldDidEndEditing:(UITextField *)textField {
    
    if (textField.tag == 22) { //金额框
        if ([textField.text componentsSeparatedByString:@"."].count == 1) { //处理009 ,09
            
            float value = textField.text.floatValue;
            textField.text = [NSString stringWithFormat:@"%.f",value];
            
        }else if ([textField.text componentsSeparatedByString:@"."].count == 2) { //处理09.，09.0，0.91
            
            if ([[[textField.text componentsSeparatedByString:@"."] lastObject] isEqualToString:@"0"]) {
                
                float value = textField.text.floatValue;
                textField.text = [NSString stringWithFormat:@"%.f",value];
            }else if([[textField.text  substringWithRange:NSMakeRange(textField.text.length -1 , 1)] isEqualToString:@"."]){
                
                float value = textField.text.floatValue;
                textField.text = [NSString stringWithFormat:@"%.f",value];
            }
        }
    }
}

#pragma  mark -cancelButtonAction

- (void)cancelButtonAction { //取消交易
    
    [self.view endEditing:YES];
    
    UIView *view_bg = [self.view.window viewWithTag:600];
    UIView *view_roll = [self.view.window  viewWithTag:800];
    
    [view_bg removeFromSuperview];
    [view_roll removeFromSuperview];
    
}
#pragma mark-forgetAction

- (void)forgetAction {
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -rightButtonAction
- (void)rightButtonAction {
    
    AssetDetailsViewController *assetDatialVC = [[AssetDetailsViewController alloc]init];
    NSLog(@"转出记录");
    
    [self.navigationController pushViewController:assetDatialVC animated:YES];
}

#pragma mark - setter method

- (NSMutableDictionary *)mutableDictionary_headerData {
    
    if (!_mutableDictionary_headerData) {
        
        _mutableDictionary_headerData = [NSMutableDictionary dictionary];
    }
    
    return _mutableDictionary_headerData;
}

- (NSMutableArray *)mutableArray_provinceList {
    
    if (!_mutableArray_provinceList) {
        
        _mutableArray_provinceList = [NSMutableArray array];
    }
    
    return _mutableArray_provinceList;
}

@end
